
import Debug.QuickCheck
import Sample

-----------------------------------------------------------------------

copyFile :: FilePath -> FilePath -> IO ()
copyFile from to =
  do contents <- readFile from
     writeFile to contents
     
display :: Show a => IO a -> IO ()
display io =
  do x <- io
     print x

--doTwice :: IO a -> IO (a,a)
doTwice io =
  do x <- io
     y <- io
     return (x,y)

--dont :: IO a -> IO ()
dont io =
  do return ()

-----------------------------------------------------------------------

data Suit = Spades | Hearts | Diamonds | Clubs
    deriving (Show,Eq)
    
suit :: Gen Suit
suit =
  oneof
  [ return Spades
  , return Hearts
  , return Diamonds
  , return Clubs
  ]    
   
-----------------------------------------------------------------------

data Rank = Numeric Integer
                   | Jack | Queen | King | Ace
  deriving (Show,Eq)

{-
rank :: Gen Rank
rank =
  oneof
  [ return Jack
  , return Queen
  , return King
  , return Ace
  , do r <- choose (2,10)
       return (Numeric r)
  ]
-}

rank :: Gen Rank
rank =
  frequency
  [ (1, return Jack)
  , (1, return Queen)
  , (1, return King)
  , (1, return Ace)
  , (9, do r <- choose (2,10)
           return (Numeric r))
  ]


-----------------------------------------------------------------------

data Card = Card Rank Suit
    deriving (Show,Eq)

card :: Gen Card
card = 
  do r <- rank
     s <- suit
     return (Card r s)    

-----------------------------------------------------------------------

data Hand = Empty | Add Card Hand
  deriving (Eq, Show)

hand :: Gen Hand
hand =
  oneof 
  [ return Empty
  , do c <- card
       h <- hand
       return (Add c h)
  ]
  
-----------------------------------------------------------------------

instance Arbitrary Suit where
  arbitrary = suit

instance Arbitrary Rank where
  arbitrary = rank
  
instance Arbitrary Card where
  arbitrary = card
  
instance Arbitrary Hand where
  arbitrary = hand
  
-----------------------------------------------------------------------
